package com.wsb.wetchat.controller;

import com.wsb.wetchat.common.CommonResult;
import com.wsb.wetchat.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wang shaobo
 * @date 2022/6/30  15:55
 */
@RestController
public class ProductController {

    @Autowired
    ProductService productService;


    @GetMapping(value = "/product/buy",produces = "application/json;charset=UTF-8")
    public CommonResult buyProduct(@RequestParam(value = "num") int num){

        if(num < 1){
            return new CommonResult(500,"数量不可小于1",null);
        }

        return productService.decreaseStock(1, num);


    }


}
